@tool
extends Node2D


@export var player: Player
@export var lvl_changed_pause: bool
@export var need_pause_nodes: Array[Node]
    

func _enter_tree() -> void:
    Global.init_player(player)

func _ready() -> void:
    RenderingServer.set_default_clear_color(Color.BLACK)

    # Input.mouse_mode = Input.MOUSE_MODE_CONFINED

    var gold: AutoPickableItem = ObjectPoolManager.op_gold.acquire()
    # add_child(gold)
    gold.global_position = Vector2.ZERO
    gold.z_index = z_index + 1

    create_item_from_pool(ObjectPoolManager.op_exp, -1, Vector2(32, 32))
    create_item_from_pool(ObjectPoolManager.op_exp, -1, Vector2(100, 32))
    create_item_from_pool(ObjectPoolManager.op_exp, -1, Vector2(100, -32))
    create_item_from_pool(ObjectPoolManager.op_exp, -1, Vector2(50, -32))

    create_item_from_pool(ObjectPoolManager.op_manual_pi, 30001, Vector2(200, 100))
    create_item_from_pool(ObjectPoolManager.op_manual_pi, 30002, Vector2(300, 100)).set_icon_transformation({"flip_h": true})
    create_item_from_pool(ObjectPoolManager.op_manual_pi, 30003, Vector2(400, 100))

    player.data.level_changed.connect(
        func(_ov: int, _nv: int) -> void:
            if not lvl_changed_pause: return
            for node in need_pause_nodes:
                node.process_mode = Node.PROCESS_MODE_DISABLED
    )

    # get_tree().get_first_node_in_group("player")


func create_item_from_pool(op: ObjectPool, id: int, pos: Vector2 = Vector2.ZERO) -> ManualPickableItem:
    var item: PickableItem = op.acquire()
    if id != -1:
        item.setup(id)
    item.global_position = pos
    item.z_index = z_index + 1
    return item
